# The following packages are required to run the codes below
# if you do not have them installed, uncomment the lines below and run them once
#install.packages("tidyverse")
#install.packages("electionsBR")
#install.packages("stringi")
#install.packages("data.table")
#install.packages("here")

# Run Scripts to download data -----

# If you want to download the raw data again, uncomment the following lines and run the download scripts.
# If the data was not obtained using a code, we provide a "how to download" file in the folder where the raw data is stored

# Download Bolsa Familia data
#source(here::here("codes","download","download_bolsa_familia.R"))

# Download data from IBGE 
#source(here::here("codes","download","download_data_IBGE.R"))

# Download data from TSE
#source(here::here("codes","download","download_data_TSE.R"))

# Download data from INEP
#source(here::here("codes","download","download_data_INEP.R")) 

# Run scripts that process electoral data from main TSE repository -----
source(here::here("codes","process","elections","clean_raw_elections.R")) 
source(here::here("codes","process","elections","create_party_weights_local_elec.R")) 
source(here::here("codes","process","elections","create_coalition_ideology_index.R")) 
source(here::here("codes","process","elections","create_margin_of_victories.R")) 
source(here::here("codes","process","elections","create_self_reported_wealth.R")) 
source(here::here("codes","process","elections","create_campaign_finance.R")) 


# Run scripts that process electoral data from old TSE repository
source(here::here("codes","process","elections","create_elections_oldsys_data.R")) 
source(here::here("codes","process","elections","create_margin_of_victories_1996_oldsys.R")) 


# Run Scripts to process city characteristics data ---------

# Run scripts to process data from IBGE 
source(here::here("codes","process","city_chars","create_gdp_deflator.R")) 
source(here::here("codes","process","city_chars","create_gdp_mun.R")) 
source(here::here("codes","process","city_chars","create_pop_mun.R")) 
source(here::here("codes","process","city_chars","create_pop_mun_by_age.R")) 
source(here::here("codes","process","city_chars","create_earnings_mun.R")) 
source(here::here("codes","process","city_chars","create_educ_levels_mun.R")) 
source(here::here("codes","process","city_chars","create_H_tiebout.R")) 
source(here::here("codes","process","city_chars","create_pea_mun.R")) 
source(here::here("codes","process","city_chars","create_race_mun.R")) 
source(here::here("codes","process","city_chars","create_urban_mun.R")) 

# Run scripts to process data from SIGA-Brasil
source(here::here("codes","process","city_chars","create_amendments_mun.R"))

# Run scripts to process data from Bolsa Familia
source(here::here("codes","process","city_chars","create_bolsa_fam.R")) 

# Run Scripts to process fiscal policy data ---------
source(here::here("codes","process","fiscalpolicy","create_constitutional_grants.R")) 
source(here::here("codes","process","fiscalpolicy","create_correspondence_ibge_siafi_ug.R")) 
source(here::here("codes","process","fiscalpolicy","create_finbra_panel.R")) 
source(here::here("codes","process","fiscalpolicy","create_fiscalpolicy_outcomes.R")) 

# Run Scripts to process welfare related outcomes data ---------
source(here::here("codes","process","welfare_outcomes","create_educational_outcomes.R")) 
source(here::here("codes","process","welfare_outcomes","create_health_outcomes.R")) 
source(here::here("codes","process","welfare_outcomes","create_law_outcomes.R")) 

# Run Scripts that creates databases in Stata (.dta) format ----
source(here::here("codes","process","create_dta_files","create_candidate_chars_dta.R")) 
source(here::here("codes","process","create_dta_files","create_demographic.R")) 
source(here::here("codes","process","create_dta_files","create_main_dataset.R")) 
source(here::here("codes","process","create_dta_files","create_main_dataset_1996.R")) 
